//
//  AJNetworkHelper.swift
//  aj
//
//  Created by leeqb on 11/15/15.
//  Copyright © 2015 powerlee. All rights reserved.
//

import UIKit

class AJNetworkHelper: CBNetworkHelper {
    
    static let instance = AJNetworkHelper()
    
    class func genRequestParams(serviceName: String, var parameters: [NSObject : AnyObject]!) -> [NSObject : AnyObject]! {
        var temp = [NSObject : AnyObject]()
        temp["serviceName"] = serviceName
        
        /*  调用平台（Android,IOS,Web）
        *   001 代表Android客户端
        *   002 代表IOS客户端
        *   003 代表Web客户端
        *   004 代表Wap客户端
        */
        temp["callType"] = "002"
        parameters["ucode"] = "8888"
        parameters["userId"] = userId
        temp["params"] = parameters
        
        let jsonData = try? NSJSONSerialization.dataWithJSONObject(temp, options: [])
        let jsonStr = String(data: jsonData!, encoding: NSUTF8StringEncoding)
        let finalParameters = ["jsonRequest": jsonStr!]
        
        return finalParameters
    }
    
    override func post(serviceName: String, parameters: [NSObject : AnyObject]!, success: ((AFHTTPRequestOperation!, AnyObject!) -> Void)!, failed: ((AFHTTPRequestOperation!, NSError!) -> Void)!, finally: (() -> Void)!) {
        let finalParams = AJNetworkHelper.genRequestParams(serviceName, parameters: parameters)
        
        let url = AJUrlHelper.getAppServerUrl()
        CBNetworkHelper.shareInstance().post(url, parameters: finalParams, success: success, failed: failed, finally: finally)
    }
    
}
